package com.example.compose.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.unit.dp
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.example.compose.R
import com.google.accompanist.coil.rememberCoilPainter

/**
 * Created by Android Studio.
 * User: HuangWeiQiang
 * Date: 2021/4/22
 * Time: 14:49
 */
class DetailFragment : Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        requireActivity().supportFragmentManager
        return ComposeView(requireContext()).apply {
            setContent {
//                DetailView("", "", requireActivity().supportFragmentManager)
            }
        }
    }

//    @Composable
//    fun DetailView(name: String, time: String, fragment: FragmentManager) {
//        MaterialTheme {
//            val typography = MaterialTheme.typography
//            Image(
//                painter = rememberCoilPainter(request = R.drawable.ic_baseline_arrow_back_ios_24),
//                contentDescription = "back",
//                modifier = Modifier.clickable {
//                    fragment.beginTransaction().remove(this).commit()
//                }
//            )
//            Row(
//                verticalAlignment = Alignment.CenterVertically,
//                modifier = Modifier.padding(10.dp)
//            ) {
//                Image(
//                    painter = rememberCoilPainter(request = R.drawable.image),
//                    contentDescription = "image",
//                    contentScale = ContentScale.Crop,
//                    modifier = Modifier
//                        .width(300.dp)
//                        .height(300.dp)
//                        .clip(shape = RoundedCornerShape(5.dp))
//                )
//                //Column函数可让您垂直堆叠元素
//                Column(modifier = Modifier.padding(start = 10.dp)) {
//                    Text(text = name, style = typography.h6)
//                    Text(text = "时间：$time", style = typography.body2)
//                }
//            }
//        }
//    }
}